﻿using System;
using Newtonsoft.Json;

namespace OrkutAPILibrary.Entities
{
    /// <summary>
    /// Orkut Friend Request Class
    /// </summary>
    public class OrkutFriendRequest
    {
        /// <summary>
        /// Gets or sets the message from requester.
        /// </summary>
        /// <value>The message from requester.</value>
        [JsonProperty(PropertyName = "body")]
        public string MessageFromRequester { get; set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>The type.</value>
        [JsonProperty(PropertyName = "type")]
        public string Type { get; set; }

        /// <summary>
        /// Gets or sets from user id.
        /// </summary>
        /// <value>From user id.</value>
        [JsonProperty(PropertyName = "fromUserId")]
        public string FromUserId { get; set; }

        private static readonly DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

        /// <summary>
        /// Gets or sets the request time.
        /// </summary>
        /// <value>The request time.</value>
        public DateTime RequestTime { get; set; }

        [JsonProperty(PropertyName = "time")]
        private string _requestTime
        {
            get
            {
                return (RequestTime - unixEpoch).TotalSeconds.ToString();
            }
            set
            {
                RequestTime = unixEpoch.AddSeconds(Convert.ToInt32(value));
            }
        }

        /// <summary>
        /// Gets or sets the requester.
        /// </summary>
        /// <value>The requester.</value>
        [JsonProperty(PropertyName = "fromUserProfile")]
        public OrkutPerson Requester { get; set; }
    }
}
